package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.TeacherMapper;
import com.example.projectcode.model.Teacher;
import com.example.projectcode.service.TeacherService;
import com.example.projectcode.vo.TeacherVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.QueryTimeoutException;
import org.springframework.stereotype.Service;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {


    @Autowired
    private TeacherMapper teacherMapper;
    @Override
    public boolean insertTeacher(Teacher teacher) {
        return baseMapper.insert(teacher)>0;
    }

    @Override
    public int deleteTeacherById(Integer id) {
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.eq("teaId",id);
       return baseMapper.delete(teacherQueryWrapper);

    }

    @Override
    public int updateTeacher(Teacher teacher) {
        QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("teaId",teacher.getTeaId());
       return baseMapper.update(teacher,queryWrapper);

    }

    @Override
    public Teacher selectOneTeacher(String teaUsername, String teaPassword) {
            return baseMapper.selectOne(new QueryWrapper<Teacher>()
                    .eq("teaUsername",teaUsername)
                    .eq("teaPassword",teaPassword));
    }

    @Override
    public int updatePasswordById(Integer teaId, String teaPassword) {
        int result = teacherMapper.updatePasswordByTeaId(teaId,teaPassword);
        return result;
    }

    @Override
    public int updateTeacherByVo(TeacherVo teacherVo) {
        return teacherMapper.updateTeacherByVo(teacherVo);
    }


}
